﻿create procedure [dbo].[usp_TargetSiteInsert]
	@IsAbstract bit
	, @IsAssembly bit
	, @IsConstructor bit
	, @IsFamily bit
	, @IsFamilyAndAssembly bit
	, @IsFamilyOrAssembly bit
	, @IsFinal bit
	, @IsHideBySignature bit
	, @IsPrivate bit
	, @IsPublic bit
	, @IsSpecialName bit
	, @IsStatic bit
	, @IsVirtual bit
as

begin try
	
	begin transaction
	
		if not exists(select * from [dbo].[TargetSite] where [IsAbstract] = @IsAbstract and
			                                             [IsAssembly] = @IsAssembly and 
				                                         [IsConstructor] = @IsConstructor and
					                                     [IsFamily] = @IsFamily and
						                                 [IsFamilyAndAssembly] = @IsFamilyAndAssembly and
						                                 [IsFamilyOrAssembly] = @IsFamilyOrAssembly and
						                                 [IsFinal] = @IsFinal and
						                                 [IsHideBySignature] = @IsHideBySignature and
						                                 [IsPrivate] = @IsPrivate and
						                                 [IsPublic] = @IsPublic and
						                                 [IsSpecialName] = @IsSpecialName and
						                                 [IsStatic] = @IsStatic and
						                                 [IsVirtual] = @IsVirtual)
			begin
										                              
				insert [dbo].[TargetSite]
				(
					IsAbstract
					, IsAssembly
					, IsConstructor
					, IsFamily
					, IsFamilyAndAssembly
					, IsFamilyOrAssembly
					, IsFinal
					, IsHideBySignature
					, IsPrivate
					, IsPublic
					, IsSpecialName
					, IsStatic
					, IsVirtual				
			    )
				values
				(
					@IsAbstract
					, @IsAssembly
					, @IsConstructor
					, @IsFamily
					, @IsFamilyAndAssembly
					, @IsFamilyOrAssembly
					, @IsFinal
					, @IsHideBySignature
					, @IsPrivate
					, @IsPublic
					, @IsSpecialName
					, @IsStatic
					, @IsVirtual
				)
				
				select TargetSiteId, ConcurrencyId, Created, Updated from [dbo].[TargetSite] where @@rowcount > 0 and TargetSiteId = scope_identity()
			
			end
			
		else
			
			begin
			
				select TargetSiteId, ConcurrencyId, Created, Updated from [dbo].[TargetSite] where [IsAbstract] = @IsAbstract and
																							       [IsAssembly] = @IsAssembly and 
																								   [IsConstructor] = @IsConstructor and
																								   [IsFamily] = @IsFamily and
																								   [IsFamilyAndAssembly] = @IsFamilyAndAssembly and
																								   [IsFamilyOrAssembly] = @IsFamilyOrAssembly and
																								   [IsFinal] = @IsFinal and
																								   [IsHideBySignature] = @IsHideBySignature and
																								   [IsPrivate] = @IsPrivate and
																								   [IsPublic] = @IsPublic and
																								   [IsSpecialName] = @IsSpecialName and
																								   [IsStatic] = @IsStatic and
																								   [IsVirtual] = @IsVirtual
			end
	
	commit transaction

end try
	
begin catch
	if @@trancount > 0
	begin
		rollback transaction;
	end
	execute [dbo].[usp_SqlErrorInsert]
end catch


